package cloud.health.common.file.application.handler;

import cloud.health.common.file.infrastructure.RuntimeUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 管理服务器管道处理
 */
@Slf4j
@Component
public class ManageChannelInboundHandler extends ChannelInboundHandlerAdapter {


    public void channelActive(ChannelHandlerContext ctx) {

    }

    public void channelInactive(ChannelHandlerContext ctx) {
        ctx.close();
    }

    @SneakyThrows
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {

    }

    private void print(long free) {
        RuntimeUtil.printGC();
        log.info("free = {}, MiB, cost = {}MiB",
                BigDecimal.valueOf(RuntimeUtil.freeMemory()).divide(BigDecimal.valueOf(1024 * 1024), 2, BigDecimal.ROUND_HALF_UP),
                BigDecimal.valueOf(RuntimeUtil.freeMemory() - free).divide(BigDecimal.valueOf(1024 * 1024), 2, BigDecimal.ROUND_HALF_UP));
    }

}
